﻿using B.S.Traceability.Myproject.Domain;
using B.S.Traceability.Myproject.ErrorCode;
using B.S.Traceability.Myproject.infrastructure.Interface;
using B.S.Traceability.MyRead.Api.Appicant.Command.InformationCommand;
using B.S.Traceability.MyRead.Api.DTOs;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace B.S.Traceability.MyRead.Api.Appicant.CommandHandler.InformationCommandHandler
{
    public class GetShopCommandHandler : IRequestHandler<GetShopCommand, APIResult<List<ShopMondel>>>
    {
        private readonly IBaseRepository<ShopMondel> shopRepos;

        public GetShopCommandHandler(IBaseRepository<ShopMondel> shopRepos)
        {
            this.shopRepos = shopRepos;
        }

        public async Task<APIResult<List<ShopMondel>>> Handle(GetShopCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<ShopMondel>> result = new APIResult<List<ShopMondel>>();

            var list = await shopRepos.GetAll().Result.Where(x => x.Status == 1).ToListAsync();


            //////条件查询///////

          
            if (list.Count() < 0)
            {
                result.Code = APIEnum.查询失败;
                result.Msg = APIEnum.查询失败.ToString();
                result.data = list.ToList();
            }
            else
            {
                result.Code = APIEnum.查询成功;
                result.Msg = APIEnum.查询成功.ToString();
                result.data = list.ToList();
            }

            return await Task.FromResult(result);
        }


    }
}

